#!/usr/bin/perl
#
# Count admin operations from Weblog
#
open(LOG, "grep -h -v ' - - ' /var/log/httpd/access_log* |")
    || die "Unable to open grep";
while (<LOG>) {
    if (/^(\S+) \S+ (\S+) \[.* (\d+) (\d+|-)/) {
	if ($3 == 401) {
	    ++ $denycount;
	} else {
	    ++ $opcount{$2};
	    ++ $accesscount{"$2 $1"};
	}
    } else {
	warn "Unparsed line: $_";
    }
}
print "$denycount attempted logins denied\n";
print "Operations:\n";
for $user (sort(keys(%opcount))) {
    printf "%5d %s\n", $opcount{$user}, $user;
}
print "Access from:\n";
for $user (sort(keys(%accesscount))) {
    printf "%5d %s\n", $accesscount{$user}, $user;
}

	
